package com.bruce.testxlog;

import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;



/**
 * APK信息
 */
public class ApkInfo {
    /**
     * apk包名
     */
    public static final String PACKAGE_NAME = getPackageName();
    /**
     * apk版本号
     */
    public static final int VERSION_CODE = getVersionCode();
    /**
     * apk版本名称
     */
    public static final String VERSION_NAME = getVersionName();

    private static String getPackageName() {
        return XLogApp.getContext().getPackageName();
    }

    private static int getVersionCode() {
        int versionCode = 0;
        try {
            PackageInfo packageInfo = XLogApp.getContext().getPackageManager().getPackageInfo(XLogApp
                    .getContext().getPackageName(), 0);
            versionCode = packageInfo.versionCode;
        } catch (NameNotFoundException e) {
            e.printStackTrace();
        }
        return versionCode;
    }

    private static String getVersionName() {
        String versionName = null;
        try {
            PackageInfo packageInfo = XLogApp.getContext().getPackageManager().getPackageInfo(XLogApp
                    .getContext().getPackageName(), 0);
            versionName = packageInfo.versionName;
        } catch (NameNotFoundException e) {
            e.printStackTrace();
        }
        return versionName;
    }

    ;


}
